/**
 * 
 */
package tp.pr5;

/**
 * An enum class that represents the compass directions (North, east, south and west) plus a value that represents an unknown direction.
 * @author VICTOR & HENAR
 */
public enum Direction {
	NORTH {
		@Override
		public Direction rotate(Rotation rotation) {
			return rotation == Rotation.LEFT?WEST:EAST;
		}
	},EAST {
		@Override
		public Direction rotate(Rotation rotation) {
			return rotation == Rotation.LEFT?NORTH:SOUTH;
		}
	},SOUTH {
		@Override
		public Direction rotate(Rotation rotation) {
			return rotation == Rotation.LEFT?EAST:WEST;
		}
	},WEST {
		@Override
		public Direction rotate(Rotation rotation) {
			return rotation == Rotation.LEFT?SOUTH:NORTH;
		}
	},UNKNOWN {
		@Override
		public Direction rotate(Rotation rotation) {
			return null;
		}
	};
	
	
	public abstract Direction rotate(Rotation rotation);
		
	/**
	 * return the back direction
	 * @return Direction
	 */
	public Direction opposite()
	{
		Direction[] direction=Direction.values();
		int invert;
		if(this.ordinal()-2<0)
		{
			invert=this.ordinal()+2;
		} 
		else 
		{
			invert=Math.abs(this.ordinal()-2);
		}
		return direction[invert];

	}
}
